import procpy
import wutmp

fmt = r"%-8s %-8s %-18s %-8s %-7s %-7s %-7s   %s"

print procpy.uptime()
print fmt % ("USER", "TTY", "FROM", "LOGIN@", "IDLE", " JCPU", " PCPU", "WHAT")

u = wutmp.wgetutent()
for i in u:
   hostname=''

   #what = procpy.readproc_by_pid(i[3])[9]
   #what = i[8]

   if not len(i['host']):
      hostname="-"
   else:
      hostname=i['host']

   print fmt % (i['user'], i['line'], hostname,
                str(i['login'][3])+':'+str(i['login'][4]),
                i['idle'], i['jcpu'], i['pcpu'], i['process'])
